package com.lmn.bus.rocketmq.endpoint;

import com.lmn.bus.rocketmq.event.MyRemoteApplicationEvent;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.Selector;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.cloud.bus.endpoint.AbstractBusEndpoint;
import org.springframework.context.ApplicationEventPublisher;

import java.util.HashMap;
import java.util.Map;


@Endpoint(id = "mybus")
public class MyBusEndpoint extends AbstractBusEndpoint {

    public MyBusEndpoint(ApplicationEventPublisher context, String appId) {
        super(context, appId);
    }

    @WriteOperation
    public void mybusWithDestination(@Selector String destination) {
        Map<String, String> params = new HashMap<>();
        params.put("key1", "value1");
        publish(new MyRemoteApplicationEvent(this, getInstanceId(), destination, params));
    }

    @WriteOperation
    public void mybus() {
        Map<String, String> params = new HashMap<>();
        params.put("key2", "value2");
        publish(new MyRemoteApplicationEvent(this, getInstanceId(), null, params));
    }
}
